{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/public_file/css/PersonnelChooser.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .add_background {
            background: #A9A9A9;
        }

        tr {
            height: 35px;
        }

        th {
            text-align: center;
        }

        table {
            table-layout: fixed;
        }

        td:first-child, th:first-child {
            position: sticky;
            left: 0; /* 首行永远固定在左侧 */
            z-index: 1;
        }

        thead tr th {
            position: sticky;
            top: 0; /* 列首永远固定在头部  */
            background-color: #E8E8E8;
        }

        th:first-child {
            z-index: 2;
        }

        .li-class {
            list-style: none;
            margin-top: 2%;
            color: #0b0b0b;
            cursor: pointer;
        }

        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }

        .search input {
            vertical-align: middle;
            float: left;
        / / 左浮动 flex: 4;
            height: 30px;
            width: 230px;
            outline: none;
            border: 1px solid #0070c1;
            box-sizing: border-box;
        / / 盒子模型，怪异IE盒子模型，width = content + border * 2 + padding * 2 padding-left: 10 px;
            border-bottom-left-radius: 3px;
            border-top-left-radius: 3px;
        }

        .search button {
            float: right;
            flex: 1;
            height: 30px;
            width: 70px;
            line-height: 30px;
            background-color: #0070c1;
            color: white;
            border-style: none;
            outline: none;
            border-bottom-right-radius: 3px;
            border-top-right-radius: 3px;
        }

        .search button i {
            font-style: normal;
        }

        .search button:hover {
            font-size: 16px;
        }

        #addForm {
            width: 600px;
            height: 400px;
            background: #F5F5F5;
            position: absolute;
            border: #dfdfdf solid 1px;
            margin: auto;
            border-radius: 3px;
            top: 50%;
            left: 50%;
            /* 实现鼠标拖拽使用css3效果 */
            transform: translate(-50%, -50%);
            z-index: 10100;
            font-size: 0;
        }

        #title {
            display: flex;
            justify-content: space-between;
            box-sizing: border-box;
            padding: 0 10px;
            height: 40px;
            color: #0b0b0b;
            cursor: move;
            /*border: #dfdfdf solid 1px;*/
            width: 100%;background: #f4f7fa;border-top-left-radius: 5px;border-top-right-radius: 5px;
        }

        .shade1 {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(36, 36, 36, 0.5);
            display: none;
            z-index: 10000;
        }
        .search-input {
            width: 95%;
            height: 30px;
            border-radius: 3px;
            border: #cfcfcf solid 1px;
            background: url(../../static/personal_center/img/input_search.png) no-repeat 4px 5px;
            background-size: 8%;
            background-color: white;
            padding-left: 30px;
            outline: none;
            font-size: 14px;
        }
        #processed div {
            padding-left: 2%;
        }
        #processed div:hover {
            background: #cfcfcf;
        }
        #ThreeNavigation div {
            padding-left: 2%;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div style="width: 100%;height: 40px;background: white;border-bottom: #A9A9A9 solid 0.5px;line-height: 40px;padding-left: 1%;color: black;">

        <div id="summit_button" style="float: right;width: 110px;text-align: center;height: 100%;">
            <button id="summ_id" onclick="summit_fun()"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;color: white;background-color: #1E90FF;line-height: 30px;">
                提&nbsp;&nbsp;交
            </button>
        </div>
        <div id="save_button" style="float: right;width: 110px;text-align: center;height: 100%;">
            <button id="save_id" onclick="save_fun()"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;color: white;background-color: #1E90FF;line-height: 30px;">
                保&nbsp;&nbsp;存
            </button>
        </div>
    </div>

    <hr>

    <div style="width: 100%;height: 95%;background: white;">
        <div style="width: 100%;height: 40px;line-height: 50px;text-align: center;">
            <h3 id="manuscript_title" style="line-height: 50px;">{{ title }}</h3>
        </div>
        <hr>
        <div style="width: 90%;margin-left: 5%;height: 90%;overflow: auto;margin-top: 1%;border-top: #cccccc solid 1px;">
            <div style="width: 100%;">
                <table id="fa_type" style="width: 100%; {% if obj.type not in tmpe_list1 %}display: none{% endif %};">
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            发文类型
                        </td>
                        <td id="fwnx"
                            style="width: 60%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;">
                            <span><input type="radio" name="XZ_gw_type" value="京医文"
                                         {% if obj.type == 'h' %}checked{% endif %}> 京医文</span>
                            <span style="margin-left: 15px;"><input type="radio" name="XZ_gw_type" value="京医发"
                                                                    {% if obj.type == 'f' %}checked{% endif %}> 京医发</span>
                        </td>
                        <td id="qf_td"
                            style="width: 10%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            签发领导
                        </td>
                        <td id="qf_td1"
                            style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">
                            <select name="" id="qf_people" style="width: 100%;height: 100%;border: none;">
                                <option value="">请选择签发领导</option>
                                {% for qf_leader in qf_leaders %}
                                    <option value="{{ qf_leader.id }}" {% if obj.qf_people_id == qf_leader.id %}
                                            selected="selected" {% endif %}>{{ qf_leader.real_name }}</option>
                                {% endfor %}
                            </select>
                        </td>
                    </tr>
                </table>
                <table style="width: 100%;">
                    <tr id="qf_no" style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            拟稿科室
                        </td>
                        <td id="ngks"
                            style="width: 40%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;" {% if obj.type in tmpe_list2 %}onclick="show_model()"{% endif %}>{{ obj.drafter_company }}</td>
                        <td style="width: 10%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            拟&nbsp;&nbsp;稿&nbsp;人
                        </td>
                        <td id="ngr"
                            style="width: 10%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;" {% if obj.type in tmpe_list2 %} onclick="model_line()" {% endif %}>{{ obj.drafter }}</td>
                        <td style="width: 10%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            文&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号
                        </td>
                        <td id="gwwh"
                            style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">{{ obj.document_number }}</td>
                    </tr>
                </table>
                <table id="fenguan_yes" style="width: 100%; {% if obj.type not in tmpe_list2 %}display: none;{% endif %}">
                    <tr style="width: 100%;">
{#                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">#}
{#                            <span style="color: red;">* </span>标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题#}
{#                        </td>#}
{#                        <td id="gwbt1"#}
{#                            style="width: 40%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;"#}
{#                            contenteditable="true"></td>#}
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            发&nbsp;&nbsp;起&nbsp;人
                        </td>
                        <td id="fqr"
                            style="width: 40%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;">{{ obj.apply_user.real_name }}</td>
                        <td style="width: 10%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            <span style="color: red;">* </span>分管领导
                        </td>
                        <td style="width: 35%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">
                            <select name="" id="fg_people" style="width: 100%;height: 100%;border: none;">
                                <option value="">请选择分管领导</option>
                                {% for leader in leaders %}
                                    <option value="{{ leader.id }}" {% if obj.fg_people_id == leader.id %}
                                            selected="selected" {% endif %}>{{ leader.real_name }}</option>
                                {% endfor %}
                            </select>
                        </td>
                    </tr>
                </table>
                <table style="width: 100%;">
                    <tr id="fenguan_no" style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            <span style="color: red;">* </span>标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题
                        </td>
                        <td id="gwbt"
                            style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;"
                            contenteditable="true">{{ obj.conference_memo_text }}</td>
                    </tr>
                    {% if obj.type == "f" or obj.type == "h" %}
                        <tr style="width: 100%;">
                            <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                                <span style="color: red;">* </span>印&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;份
                            </td>
                            <td id="yf"
                                style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;"
                                contenteditable="true">{{ obj.servings }}
                            </td>
                        </tr>
                    {% endif %}
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            <span style="color: red;">* </span>主&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送
                        </td>
                        <td id="zs"
                            style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;"
                            contenteditable="true">{{ obj.main_company }}</td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                            <span style="color: red;visibility: hidden;">* </span>抄&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送
                        </td>
                        <td id="cs"
                            style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;"
                            contenteditable="true">{{ obj.vice_company }}</td>
                    </tr>
                    {% if obj.type == "f" or obj.type == "g" or obj.type == "h" %}
                        <tr style="width: 100%;">
                            <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">
                                <span style="color: red;visibility: hidden;">* </span>依&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;据
                            </td>
                            <td id="yj"
                                style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;"
                                contenteditable="true">{{ obj.gist }}</td>
                        </tr>
                    {% endif %}
                    {% if obj.type == "d" %}
                        <tr id="countersign" style="width: 100%;">
                            <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">会签领导</td>
                            <td style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">
                                {% for jointly in sign_jointly %}
                                    <div style="width: 80px;display: inline-block;vertical-align: top;"><input type="checkbox" class="read_leadership" value="{{ jointly.id }}"> {{ jointly.real_name }}</div>
                                {% endfor %}
                            </td>
                        </tr>
                    {% endif %}
                </table>
            </div>
            <div style="width: 100%;">
                <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                    <span style="color: red;">* </span>上传文件
                    <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                        上传文件
                        <input type="file" name="regular_main_body" id="regular_main_body"
                               onchange="upload_accessory('file1', 'regular_main', 'regular_main_body')">
                    </a>
                </div>
                <table style="width: 100%;">
                    <thead>
                    <tr>
                        <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">文件名称</td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">文件大小</td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">上传时间</td>
                        <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">上传人员</td>
                        <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作</td>
                    </tr>
                    </thead>
                    <tbody style="overflow: auto;" id="regular_main">
                    {% for record in file_list %}
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">{{ forloop.counter }}</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_name }}</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_size }}</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.upload_time }}</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.uploader }}</td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;"><a
                                    target='_blank' href="{{ record.file_path }}">查看</a> | <a style="color: red;"
                                                                                              href='#'
                                                                                              onclick='RemoveTr(this, "party_main", {{ record.id }})'>删除</a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div id="addForm-fenfa" class="shade1">
        <div id="addForm">
            <!-- 标题 -->
            <div id="title">
                <h5 style="line-height: 40px;width: 15%;margin-left: 1%;display: inline-block;font-size: 14px;">选择科室</h5>
                <span onclick="close_models1()" style="float: right;line-height: 50px;padding-right: 2%;cursor: pointer;"><i class="iconfont icon-quchu"></i></span>
            </div>
            <hr>
            <div style="width: 55%;height: 350px;vertical-align: top;left: 0;display: inline-block;border-right: #cfcfcf solid 1px;">
                <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                    <input id="search_data1" onkeydown="search_dep()" class="search-input" type="text" placeholder="搜索" autocomplete="off">
                </div>
                <div id="processed" style="width: 100%;height: 300px;overflow: auto;">
                    {% for company in company_list %}
                        <div style="width: 100%;height: 30px;line-height: 30px;font-size: 14px;color: #0b0b0b;">
                            <input class="check_box1" id="{{ company.id }}" type="checkbox" onclick="check_dep_ff('{{ company.name }}', '{{ company.id }}')"> {{ company.name }}
                        </div>
                    {% endfor %}
                </div>
            </div>

            <div style="width: 43%;height: 360px;vertical-align: top;left: 0;display: inline-block;">
                <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;font-size: 14px;">
                    已选择科室
                </div>
                <div id="processed_prople" style="width: 100%;height: 265px;overflow: auto;padding-left: 2%;">

                </div>
                <div style="width: 100%;height: 40px;text-align: center;">
                    <button onclick="Distribution_department()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #1E90FF solid 1px;background: #1E90FF;color: white;width: 80px;letter-spacing: 4px;font-size: 14px;">
                        提交
                    </button>
                    <button onclick="close_models1()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #cfcfcf solid 1px;width: 80px;letter-spacing: 4px;margin-left: 15px;font-size: 14px;">
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div id="staff-select" class="shade">
        <div id="staff-model" style="width: 100%;height: 100%;position: absolute;">
            <div style="width: 900px;height: 500px;background: #F5F5F5;z-index: 10000;position: absolute;top: 50%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #dfdfdf solid 1px;">
                <div id="staff-box" style="width: 100%;height: 40px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 20%;margin-left: 1%;display: inline-block;line-height: 40px;font-size: 14px;">
                        选择人员
                    </div>
                    <span onclick="close_model()" style="float: right;padding-right: 2%;cursor: pointer;line-height: 40px;">
                        <i class="iconfont icon-quchu"></i>
                    </span>
                </div>
                <div style="height: 460px;width: 100%;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 70px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div id="dep" class="navigation navigation_color" onclick="change_navigation(this)">部门</div>
                        <div id="limits" class="navigation" onclick="change_navigation(this)">权限</div>
                        <div id="fun" class="navigation" onclick="change_navigation(this)">职能</div>
                    </div>
                    <div style="width: 200px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div style="width: 100%;height: 50px;line-height: 50px;">
                            <input id="SearchDep" onkeydown="SearchDepartment()" class="search_input" type="text" placeholder="搜索" autocomplete="off" style="width: 95%;">
                        </div>
                        <div id="SecondaryNavigation" style="width: 100%;height: 403px;line-height: 50px;overflow: auto;"></div>
                    </div>
                    <div style="width: 200px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                            <input type="checkbox" id="select-all" onclick="SelectAll(this)">
                            <input id="SearchPeo" onkeydown="SearchProple()" class="search_input" type="text" placeholder="搜索" autocomplete="off" style="width: 87%;">
                        </div>
                        <div id="ThreeNavigation" style="width: 100%;height: 403px;line-height: 50px;overflow: auto;"></div>
                    </div>
                    <div style="width: 370px;height: 100%;display: inline-block;vertical-align: top;overflow: auto">
                        <div style="width: 100%;height: 40px;text-align: left;font-size: 14px;line-height: 40px;">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;已选 <span id="selected-number">0</span> 人
                        </div>
                        <div id="selected-div" style="width: 100%;font-size: 14px;height: 370px;overflow: auto;line-height: 20px;">

                        </div>
                        <div style="width: 100%;font-size: 14px;height: 40px;text-align: center;">
                            <button onclick="IdentifyPersonnel()" style="width: 100px;height: 30px;line-height: 25px;text-align: center;letter-spacing: 5px;border-radius: 3px;border: #cfcfcf solid 1px;font-size: 14px;cursor: pointer;margin-top: 10px;">完成</button>
                            <button onclick="close_model()" style="margin-left: 15px;width: 100px;height: 30px;line-height: 25px;text-align: center;color: #0abb78;letter-spacing: 5px;border-radius: 3px;font-size: 14px;border: #cfcfcf solid 1px;cursor: pointer;margin-top: 10px;">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}


{% block script %}
    <script src="../../static/public_file/js/PersonnelChoosersNew.js" type="text/javascript" charset="gb2312"></script>
    <script>
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
        };

        let title = document.querySelector("#title");
        let addForm = document.querySelector("#addForm");

        title.addEventListener("mousedown", function (e) {
            let x = e.pageX - addForm.offsetLeft;
            let y = e.pageY - addForm.offsetTop;

            document.addEventListener("mousemove", move);

            function move(e) {
                addForm.style.left = e.pageX - x + 'px';
                addForm.style.top = e.pageY - y + 'px';
            }

            document.addEventListener("mouseup", function (e) {
                document.removeEventListener("mousemove", move);
            })
        });

        var department = "{{ department | safe }}";
        var realname = "{{ realname | safe }}";

        function summit_fun() {
            var re = /^[0-9]+.?[0-9]*/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/
            var gw_type = '{{ obj.type }}'
            var ngks = document.getElementById("ngks").innerText;
            var ngr = document.getElementById("ngr").innerText;
            var gwwh = document.getElementById("gwwh").innerText;
            var gwbt = document.getElementById("gwbt").innerText;
            var zs = document.getElementById("zs").innerText;
            var cs = document.getElementById("cs").innerText;
            var myselect = document.getElementById("fg_people");
            var index = myselect.selectedIndex;
            var fg_people = myselect.options[index].value;

            var qf_myselect = document.getElementById("qf_people");
            var qf_index = qf_myselect.selectedIndex;
            var qf_people = qf_myselect.options[qf_index].value;
            if (gw_type === 'f' || gw_type === 'h') {
                var yf = document.getElementById("yf").innerText;
            }
            if (gw_type === 'f' || gw_type === 'g' || gw_type === 'h'){
                gwbt = document.getElementById("gwbt").innerText;
                if (!fg_people){
                    alert("分管领导不能为空！")
                    return false
                }
                if (!ngr){
                     alert("请选择拟稿人！")
                    return false
                }
                if (gw_type === 'f' || gw_type === 'h'){
                    if (!qf_people){
                        alert("请选择签发领导！")
                        return false
                    }
                }
            }
            if (yf) {
                if (!re.test(yf)) {
                    alert("打印份数必须是数字！")
                    return false
                }
            }
            if (!zs){
                alert("主送不能为空！")
                return false
            }
            if (!gwbt){
                alert("标题不能为空！")
                return false
            }
            var t_table = document.getElementById('regular_main').children.length;
            if (t_table === 0){
                alert("请上传正文！")
                return false
            }
            var read_leadership_list = document.getElementsByClassName('read_leadership');
            var leaders_id_str = '';
            for (var id_str=0; id_str<read_leadership_list.length; id_str++) {
                if (read_leadership_list[id_str].checked) {
                    leaders_id_str = leaders_id_str + read_leadership_list[id_str].value + ','
                }
            }
            if (!leaders_id_str && gw_type === 'd') {
                alert("请选择会签人员！")
                return false
            }
            if (gw_type === 'h' || gw_type === 'g' || gw_type === 'f') {
                var yj = document.getElementById("yj").innerText;
                var send_str = "id=" + String({{ obj.id }}) + "&type=" + String('{{obj.type}}') + "&document_number=" + gwwh + "&main_company=" + zs + "&vice_company=" + cs + "&servings=" + yf + "&conference_memo_text=" + gwbt + "&fg_people=" + fg_people + "&drafter=" + String(ngr) + "&drafter_company=" + String(ngks) + "&qf_people=" + String(qf_people) + "&gist=" + String(yj);
            } else {
                send_str = "id=" + String({{ obj.id }}) + "&type=" + String('{{obj.type}}') + "&document_number=" + gwwh + "&main_company=" + zs + "&vice_company=" + cs + "&servings=" + yf + "&conference_memo_text=" + gwbt + "&fg_people=" + fg_people + "&drafter=" + String(ngr) + "&drafter_company=" + String(ngks) + "&qf_people=" + String(qf_people);
            }
            send_str = send_str + "&leaders_id_str=" + leaders_id_str
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/conference_memo_index_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(send_str);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        if (JsonDate['code']===200) {
                            alert("提交成功！")
                            window.location.href = "/personal-center/my_draft.html";
                        }else {
                            alert(JsonDate['message'])
                        }
                    }
                }
             };
        }

        function save_fun() {
            var type_str = '{{ obj.type }}'
            var re = /^[0-9]+.?[0-9]*/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/
            var ngks = document.getElementById("ngks").innerText;
            var ngr = document.getElementById("ngr").innerText;
            var gwwh = document.getElementById("gwwh").innerText;
            var gwbt = document.getElementById("gwbt").innerText;
            var yf = document.getElementById("yf").innerText;
            var zs = document.getElementById("zs").innerText;
            var cs = document.getElementById("cs").innerText;
            var myselect = document.getElementById("fg_people");
            var index = myselect.selectedIndex;
            var fg_people = myselect.options[index].value;
            var qf_myselect = document.getElementById("qf_people");
            var qf_index = qf_myselect.selectedIndex;
            var qf_people = qf_myselect.options[qf_index].value;
            if (type_str === 'h' || type_str === 'g' || type_str === 'f') {
                var yj = document.getElementById("yj").innerText;
                var send_str = "id=" + String({{ obj.id }}) + "&type=" + String('{{obj.type}}') + "&document_number=" + gwwh + "&main_company=" + zs + "&vice_company=" + cs + "&servings=" + yf + "&conference_memo_text=" + gwbt + "&fg_people=" + fg_people + "&drafter=" + String(ngr) + "&drafter_company=" + String(ngks) + "&qf_people=" + String(qf_people) + "&gist=" + String(yj);
            } else {
                send_str = "id=" + String({{ obj.id }}) + "&type=" + String('{{obj.type}}') + "&document_number=" + gwwh + "&main_company=" + zs + "&vice_company=" + cs + "&servings=" + yf + "&conference_memo_text=" + gwbt + "&fg_people=" + fg_people + "&drafter=" + String(ngr) + "&drafter_company=" + String(ngks) + "&qf_people=" + String(qf_people);
            }

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/conference_memo_draft_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(send_str);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        if (JsonDate['code'] === 200) {
                            alert(JsonDate['message'])
                            window.location.href = "/personal-center/my_draft.html";
                        } else {
                            alert(JsonDate['message'])
                        }
                    }
                }
            };
        }

        function show_model() {
            document.getElementById("addForm-fenfa").style.display = "table-row";
        }

        function close_models1() {
            document.getElementById("addForm-fenfa").style.display = "none";
        }

        // 删除列表
        function deltr1() {
            var tb = document.getElementById('t_table2');
            var rowNum = tb.rows.length;
            for (i = 0; i < rowNum; i++) {
                tb.deleteRow(i);
                rowNum = rowNum - 1;
                i = i - 1;
            }
        }

        var New_year = new Date().getFullYear();

        var company_list = {{ company_list | safe }};

        function search_dep() {
            var search_keyword = document.getElementById("search_data1").value;
            var processed = document.getElementById("processed");
            processed.innerHTML = "";
            console.log(company_list.length)
            for (var h = 0; h < company_list.length; h++) {
                if (company_list[h]["name"].indexOf(search_keyword) !== -1) {
                    console.log(company_list[h]["name"])
                    var div_tag = document.createElement("div");
                    div_tag.className = "div_clase";
                    div_tag.innerHTML = '<input class="check_box1" id="' + company_list[h]["id"] + '" type="checkbox" onclick="check_dep_ff(\'' + company_list[h]["name"] + '\', \'' + company_list[h]["id"] + '\')">' + company_list[h]["name"];
                    processed.appendChild(div_tag)
                }
            }
        }

        function check_dep_ff(ele_name, ele_id) {
            var processed_prople = document.getElementById("processed_prople");
            {#var span = document.createElement("span");#}
            console.log(document.getElementById(ele_id).checked)
            if (!document.getElementById(ele_id).checked) {
                document.getElementById(ele_id).checked = false;
                processed_prople.innerText = "";
            }
            if (document.getElementById(ele_id).checked) {
                {#span.innerText=ele_name;span.setAttribute("id", 'cc-'+ele_id);span.style.fontSize='14px';span.style.marginLeft="10px";#}
                processed_prople.innerText = ele_name;
                processed_prople.style.color = '#4169E1';
                processed_prople.style.fontSize = '14px';
                check_more_one_not1(ele_id);
            }
        }

        function Distribution_department() {
            var processed_prople = document.getElementById("processed_prople").innerText;

            if (!processed_prople) {
                alert("请选择拟稿科室！");
                return false
            }
            close_models1()
            document.getElementById("ngks").innerText = processed_prople;
        }

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', "{{ obj.number }}")
            form.append("source", "gw")
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id);
                        document.getElementById("regular_main_body").value="";
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function check_more_one_not1(ele_id) {
            var check_box_list = document.getElementsByClassName("check_box1");
            for (var i = 0; i < check_box_list.length; i++) {
                if (String(check_box_list[i].id) !== String(ele_id)) {
                    document.getElementById(check_box_list[i].id).checked = false;
                } else {
                    document.getElementById(check_box_list[i].id).checked = true;
                }
            }
        }

        function scrollConversationScreen() {
            $('#selected-div').scrollTop($('#selected-div')[0].scrollHeight);
        }

        function IdentifyPersonnel() {
            var prople_list = [];
            var selected_personnel_list = document.getElementsByClassName('selected-personnel');
            for (var i=0; i<selected_personnel_list.length; i++) {
                prople_list.push(selected_personnel_list[i].innerText)
            }
            document.getElementById("ngr").innerText = prople_list[0].split("(")[0];
            close_model()
        }
    </script>
{% endblock %}
